﻿using System.Collections.Generic;
using System.Linq;
using Framework.Core.Collections;
using Xunit;

namespace Framework.Tests.Core.Collections
{
    public class ConcurrentListTest
    {
        private readonly ConcurrentList<string> concurrentList = new ConcurrentList<string>();

        [Fact]
        public void Should_test_concurrent_list()
        {
            const string expected = "toto";
            concurrentList.Add(expected);

            Assert.Equal(expected, concurrentList.First());

            concurrentList.Remove(expected);
            Assert.Equal(0, concurrentList.Count);

            var strings = new string[1];
            concurrentList.CopyTo(strings, 0);

            concurrentList.Add(expected);
            Assert.True(concurrentList.Contains(expected));
            Assert.Equal(0, concurrentList.IndexOf(expected));
            concurrentList.Clear();
            Assert.Equal(0, concurrentList.Count);

            Assert.False(concurrentList.IsReadOnly);

            concurrentList.Insert(0, expected);

            Assert.Equal(1, concurrentList.Count);
            concurrentList.RemoveAt(0);
            Assert.Equal(0, concurrentList.Count);

            concurrentList.Add(expected);

            concurrentList[0] = "poeut";
            Assert.Equal(1, concurrentList.Count);

            concurrentList.Clear();

            concurrentList.AddRange(new List<string> { expected });

            Assert.Equal(1, concurrentList.Count);
            Assert.Equal(expected, concurrentList.First());
        }
    }
}
